home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / backup / kbackup-.000 / KBackup-1.2.7.tar / KBackup / src / subroutines < prev    next >
Text File  |  1996-03-27  |  18KB  |  826 lines

  1. #
  2. # /home/kbackup/.CVSROOT/KBackup/src/subroutines,v 1.23 1996/03/27 20:03:37 kbackup Exp
  3. #
  4. # This file is Copyright (C) 1995 by Karsten Ballⁿder
  5. #                Karsten.Ballueder@stud.uni-karlsruhe.de
  6. #
  7. # It is part of the KBackup package, see the file COPYING for details.
  8. #
  9. #################### MISCELLANEOUS SUBROUTINES ########################
  10.  
  11. # 1.23
  12.  
  13.  
  14. my_mt()
  15. {
  16.     if [ "$remote_mode" = YES ]
  17.     then
  18.         su "$remote_uid" -c "rsh $remote_host mt $@" 2>$STDERR
  19.     else
  20.         mt "$@" 2>$STDERR
  21.  
  22.     fi
  23.     tmp=$?
  24.         
  25.     if [ $tmp != 0  -a "$3" = "eom" ]
  26.     then
  27.         mt_try $1 $2 seod
  28.         tmp=$?
  29.     fi
  30.     check_error -dev
  31. }
  32.  
  33.  
  34.  
  35. check_config_changed()
  36. {
  37.     if [ "$Configuration_changed" = "YES" ] && \
  38.         $DIALOG --title " Configuration changed " --yesno "
  39. You have changed KBackup's configuration
  40. or option settings.
  41.  
  42. Do you want to save this configuration?
  43. This would make it the default configuration
  44. to load the next time that you start KBackup.
  45. " 11 50
  46.     then
  47.         Write_Config
  48.     fi
  49.     Configuration_changed=NO
  50. }
  51.  
  52. set_multibuf_options()
  53. {
  54.     multibuf_options="$STD_MULTIBUF_OPT"
  55.  
  56.     rm -f "$TMP/$MVOLFLAG" 2>/dev/null
  57.  
  58.     if [ "$multibuf_nblocks" = "" ]
  59.     then
  60.         multibuf_nblocks=1
  61.     fi
  62.  
  63.     if [ "$multibuf_blocksize" = "" ] || [ $multibuf_blocksize -lt 1024 ]
  64.     then
  65.         multibuf_blocksize=1024
  66.     fi
  67.  
  68.     if [ "$multibuf_seq_info" = "YES" ]
  69.     then
  70.         multibuf_options="$multibuf_options -h"    # add header
  71.     fi
  72.     echo -e "#!/bin/sh\nMOUNTPOINT=\"$MOUNTPOINT\"\ndevice=\"$device\"\nblockdev_fs_type=\"$blockdev_fs_type\"\n" >$TMP/$MBUF_SCRIPT1
  73.     cp $TMP/$MBUF_SCRIPT1 $TMP/$MBUF_SCRIPT2
  74.     if [ "$device_type" = "BLOCKDEV" ]
  75.     then
  76.         multibuf_options="$multibuf_options -F " # write endmarker as file
  77.         if [ "$1" = "WRITE" ]
  78.         then
  79.             if [ "$TTYMODE" = "YES" ]
  80.             then
  81.                 echo -e "( $MBUF_BLOCKDEV_WCMD1_TTY ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT1
  82.                 echo -e "( $blockdev_mkfs && $MBUF_BLOCKDEV_WCMD2_TTY ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT2
  83.             else
  84.                 echo -e "( $MBUF_BLOCKDEV_WCMD1 ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT1
  85.                 echo -e "( $blockdev_mkfs && $MBUF_BLOCKDEV_WCMD2 ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT2
  86.             fi
  87.         else
  88.             if [ "$TTYMODE" = "YES" ]
  89.             then
  90.                 echo -e "( $MBUF_BLOCKDEV_RCMD1_TTY ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT1
  91.                 echo -e "( $MBUF_BLOCKDEV_RCMD2_TTY ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT2
  92.                 echo -e "( $MBUF_BLOCKDEV_RCMDR_TTY ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPTR
  93.             else
  94.                 echo -e "( $MBUF_BLOCKDEV_RCMD1 ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT1
  95.                 echo -e "( $MBUF_BLOCKDEV_RCMD2 ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT2
  96.                 echo -e "( $MBUF_BLOCKDEV_RCMDR ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPTR
  97.             fi
  98.             multibuf_options="$multibuf_options -R $TMP/$MBUF_SCRIPTR "
  99.             chmod +x $TMP/$MBUF_SCRIPTR
  100.         fi
  101.         multibuf_options="$multibuf_options -c $TMP/$MBUF_SCRIPT1 "
  102.         multibuf_options="$multibuf_options -C $TMP/$MBUF_SCRIPT2 "
  103.     else
  104.         if [ "$multibuf_cmd1" != "" -a "$multibuf_cmd1" != "DEFAULT" ]
  105.         then
  106.             echo -e "( $multibuf_cmd1 ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT1
  107.             multibuf_options="$multibuf_options -c $TMP/$MBUF_SCRIPT1 "
  108.         fi
  109.         if [ "$multibuf_cmd2" != "" -a "$multibuf_cmd2" != "DEFAULT" ]
  110.         then
  111.             echo -e "( $multibuf_cmd2 ) </dev/tty >/dev/tty\n">>$TMP/$MBUF_SCRIPT2
  112.             multibuf_options="$multibuf_options -C $TMP/$MBUF_SCRIPT2 "
  113.         fi
  114.     fi
  115.     echo "touch $TMP/$MVOLFLAG" >>$TMP/$MBUF_SCRIPT2
  116.     chmod +x $TMP/$MBUF_SCRIPT1 
  117.     chmod +x $TMP/$MBUF_SCRIPT2
  118. }
  119.  
  120. GetPGPPASS()
  121. {
  122.     if [ "$scheduled" = YES -o "$PGPPASS" != "" ]
  123.     then
  124.         return
  125.     fi
  126.     PGPPASS=
  127.     um=`umask`
  128.     umask 077    # no read for others
  129.     $DIALOG --title " PGP pass phrase " --inputbox "
  130. For decrypting files using pgp(1) you need to specify a 
  131. pass phrase for unlocking your private key.
  132.  
  133. You will see what you type now, so make sure nobody can
  134. see your screen!
  135. " 16 75 2>$TMP/$DIALOGFILE
  136.     rm -f $TMP/$PHRASEFILE
  137.     cat $TMP/$DIALOGFILE >$TMP/$PHRASEFILE
  138.     echo >>$TMP/$PHRASEFILE
  139.     umask $um
  140.     # test whether input redirec works:
  141.     echo "test" >$TMP/$TMPFILE
  142.     cat 0<$TMP/$TMPFILE >/dev/null
  143.     if [ $? != 0 ]
  144.     then
  145.         rm -f $TMP/$PHRASEFILE
  146.         touch $TMP/$PHRASEFILE
  147.         export PGPPASS=`cat $TMP/$DIALOGFILE`
  148.     else
  149.         export PGPPASSFD=3
  150.     fi
  151. }
  152.  
  153. clear_PGP()
  154. {
  155.     PGPPASS=
  156.     rm -f $TMP/$PHRASEFILE
  157.     touch $TMP/$PHRASEFILE
  158. }
  159.  
  160.  
  161. choose_dir_tty()
  162. {
  163.     while :
  164.     do
  165.         echo -ne "
  166. Please enter the name of the directory.
  167. Just press enter to keep the default setting.
  168.  
  169. Default: \"$default\"
  170.  
  171. > "
  172.         read tmp
  173.         if [ -z "$tmp" ]
  174.         then
  175.             choose_dir_result="$default"
  176.         else
  177.             choose_dir_result="$tmp"
  178.         fi
  179.         if [ -d "$choose_dir_result" ]
  180.         then
  181.             return 
  182.         else
  183.             echo -e "\aNot a directory!"
  184.         fi
  185.     done
  186. }
  187.  
  188. choose_dir()
  189. {
  190.     currdir=`pwd`
  191.     default="$1"
  192.  
  193.     if [ "$TTYMODE" = "YES" ]
  194.     then
  195.         choose_dir_tty
  196.         return $?
  197.     fi
  198.  
  199.     cd "$default"
  200.  
  201.     
  202.     while :
  203.     do
  204.         find * $FIND_STD_OPT -prune \( -type d -o -type l \) -printf "\"%f\" %u \\\\\n" 2>/dev/null | sort >$TMP/$TMPFILE
  205.         echo >>$TMP/$TMPFILE
  206.         lines=14
  207.         cat - $TMP/$TMPFILE >$TMP/$TMPFILE2 <<_EOF_
  208. $DIALOG  --title " Directory selection " --menu \
  209. "Current path:\n`pwd`\nSelect \"<<ACCEPT>>\"-entry to accept current path." 23 60 $lines  "<<ACCEPT>>" "<<ACCEPT>>" .. Parent \\
  210. _EOF_
  211.  
  212.         if . $TMP/$TMPFILE2  2>$TMP/$DIALOGFILE
  213.         then
  214.             result=`cat $TMP/$DIALOGFILE`
  215.             if [ "$result" = "<<ACCEPT>>" ]
  216.             then
  217.                 choose_dir_result=`pwd`
  218.                 cd "$currdir"
  219.                 return
  220.             else
  221.                 cd "$result"
  222.             fi
  223.         else
  224.             cd "$currdir"
  225.             choose_dir_result="$default"
  226.             return 
  227.         fi
  228.     done
  229. }
  230.  
  231. write_settings()
  232. {
  233.     cat <<_EOF_
  234. #
  235. #    Configuration "$configname" for KBackup
  236. #
  237. ConfigVersion=$VERSION
  238. configname="$configname"
  239. parent="$parent"
  240. local="$local"
  241. directoriesonly="$directoriesonly"
  242. findxpertmode="$findxpertmode"
  243. findxpertflags="$findxpertflags"
  244. specifiedfilesonly="$specifiedfilesonly"
  245. compression="$compression"
  246. compress_options="$compress_options"
  247. verify_archive="$verify_archive"
  248. archive_format="$archive_format"
  249. pgpkey="$pgpkey"
  250. incremental="$incremental"
  251. ddbufsize="$ddbufsize"
  252. double_buffering="$double_buffering"
  253. device="$device"
  254. floppy_format="$floppy_format"
  255. device_type="$device_type"
  256. blockdev_fs_type="$blockdev_fs_type"
  257. blockdev_mkfs="$blockdev_mkfs"
  258. datestamp="$datestamp"
  259. resetdevice="$resetdevice"
  260. manualedit="$manualedit"
  261. followtarops="$followtarops"
  262. scheduled_only_once="$scheduled_only_once"
  263. use_multibuf="$use_multibuf"
  264. multibuf_nblocks="$multibuf_nblocks"
  265. multibuf_blksize="$multibuf_blksize"
  266. multibuf_seq_info="$multibuf_seq_info"
  267. multibuf_cmd1="$multibuf_cmd1"
  268. multibuf_cmd2="$multibuf_cmd2"
  269. use_patterns="$use_patterns"
  270. manual_command="$manual_command"
  271. restore_write_log="$restore_write_log"
  272. remote_mode="$remote_mode"
  273. remote_host="$remote_host"
  274. remote_uid="$remote_uid"
  275. CreateReport="$CreateReport"
  276. ReportCommand="$ReportCommand"
  277. AutoRewind="$AutoRewind"
  278. protect_newer="$protect_newer"
  279. afio_user_opts="$afio_user_opts"
  280. tar_user_opts="$tar_user_opts"
  281. TMP="$realTMP"
  282. if [ "\$EDITOR" = "" ] 
  283. then
  284.     EDITOR="$EDITOR"
  285. fi
  286. _EOF_
  287. }
  288.  
  289. save_configname()
  290. {
  291.     Configuration_changed=NO
  292.     cat >$HOME/$KBACKRCDEFAULT <<_EOF_
  293. #
  294. #    KBackup base configuration
  295. #
  296. kbackdir="$kbackdir"
  297. datadir="$datadir"
  298. configname="$configname"
  299. _EOF_
  300. }
  301.  
  302. save_config()
  303. {
  304.     save_configname
  305.  
  306.     mkdir $datadir/$configname 2>/dev/null
  307.  
  308.     write_settings > $datadir/$configname/Config
  309.     
  310.     if [ ! -f $datadir/$configname/Exclude_Files ] ; then
  311.         cat $datadir/$oldconfig/Exclude_Files >$datadir/$configname/Exclude_Files
  312.     fi
  313.     if [ ! -f $datadir/$configname/Include_Files ] ; then
  314.         cat $datadir/$oldconfig/Include_Files >$datadir/$configname/Include_Files
  315.     fi
  316.     if [ ! -f $datadir/$configname/Include_Patterns ] ; then
  317.         cat $datadir/$oldconfig/Include_Patterns >$datadir/$configname/Include_Patterns
  318.     fi
  319.     if [ ! -f $datadir/$configname/Exclude_Patterns ] ; then
  320.         cat $datadir/$oldconfig/Exclude_Patterns >$datadir/$configname/Exclude_Patterns
  321.     fi
  322. }
  323.  
  324. beep()
  325. {
  326.     echo -e "\a"
  327. }
  328.  
  329. ErrorBox()
  330. {
  331.     if [ $scheduled = YES ]
  332.     then
  333.         if [ -e $TMP/$MSGFILE ] ; then
  334.             echo -e "$*" >>$TMP/$MSGFILE
  335.         else
  336.             echo -e "$*" >&2
  337.         fi
  338.     else
  339.         echo -e "$*" >$TMP/$TMPFILE
  340.         lines=`wc -l <$TMP/$TMPFILE`
  341.         lines=`expr $lines + 7`
  342.         beep
  343.         $DIALOG   --title " Error " --msgbox "\n$*" $lines 60 
  344.     fi
  345.     if [ "$lines" = "8" ]
  346.     then
  347.         report "Error-Msg: $*"
  348.     else
  349.         report "Error-Msg:"
  350.         report "$*"
  351.         report "Error-Msg-End"
  352.     fi
  353. }
  354.  
  355. InfoBox()
  356. {
  357.     if [ $scheduled =  YES ]
  358.     then
  359.         if [ -e $TMP/$MSGFILE ] ; then
  360.             echo -e $* >>$TMP/$MSGFILE
  361.         else
  362.             echo -e $* >&2
  363.         fi
  364.     else
  365.         echo -e "$*" >$TMP/$TMPFILE
  366.         lines=`wc -l <$TMP/$TMPFILE`
  367.         lines=`expr $lines + 4`
  368.         $DIALOG   --title " Status " --infobox "\n$*" $lines 40
  369.     fi
  370.     if [ "$lines" = "5" ]
  371.     then
  372.         report "QInfo-Msg: $*"
  373.     else
  374.         report "QInfo-Msg:"
  375.         report "$*"
  376.         report "QInfo-Msg-End"
  377.     fi
  378. }
  379.  
  380.  
  381. MsgBox()
  382. {
  383.     if [ $scheduled =  YES ]
  384.     then
  385.         if [ -e $TMP/$MSGFILE ] ; then
  386.             echo -e $* >>$TMP/$MSGFILE
  387.         else
  388.             echo -e $* >&2
  389.         fi
  390.     else
  391.         echo -e "$*" >$TMP/$TMPFILE
  392.         lines=`wc -l <$TMP/$TMPFILE`
  393.         lines=`expr $lines + 7`
  394.         $DIALOG   --title " Status " --msgbox "\n$*" $lines 40
  395.     fi
  396.     if [ "$lines" = "5" ]
  397.     then
  398.         report "Info-Msg: $*"
  399.     else
  400.         report "Info-Msg:"
  401.         report "$*"
  402.         report "Info-Msg-End"
  403.     fi
  404. }
  405.  
  406. insert_media()
  407. {
  408.     if [ ! -f $device ] # if it is not a regular file
  409.     then
  410.         $DIALOG   --title " Status " --yesno \
  411. "Please insert backup medium in
  412. \"$device\".
  413.  
  414. Ok to continue?" 9 36
  415.     return $?
  416.     fi
  417. }
  418.  
  419. check_compress_success()
  420. {
  421.     ret="$?"
  422.     case    $compression in 
  423.         NONE)    
  424.             return $ret
  425.             ;;
  426.         GZIP|COMPRESS)    
  427.             if [ $ret = 0 -o $ret = 2 ] ; then
  428.                 return 0
  429.             else
  430.                 return 1
  431.             fi
  432.             ;;
  433.         PGP)
  434.             return $ret
  435.             ;;
  436.     esac
  437. }
  438.  
  439. #
  440. #    sets the variable $findargs so that only those files get listed
  441. #    that match the selection criteria. ALL FILENAMES RELATIVE TO 
  442. #    ".", that is: all filenames get compared against "./pattern"
  443. #    To use this properly, cd to the parent directory and do a
  444. #    echo find . $findargs >file 
  445. #    . file
  446. #
  447. build_find_arguments()
  448. {
  449.     findargs="$FIND_STD_OPTS -true"
  450.     opt1=
  451.     opt2=
  452.     opt3=
  453.     
  454.     datestamp=`cat "$datadir/$configname/DateStamp"`
  455.  
  456.     if [ $findxpertmode = YES ]
  457.     then
  458.         findargs="$findargs $findxpertflags"
  459.     else
  460.         # prepare list of files to exclude for tar(1):
  461.         echo $MOUNTPOINT>$TMP/$EXCLUDE #don't backup mountpoint
  462.         for d in `$GREP -v "^#" $datadir/$configname/Exclude_Files`
  463.         do
  464.             echo $d >>$TMP/$EXCLUDE
  465.             if [ -d $parent/$d ]
  466.             then    # for dirs: exclude all subdirs as well
  467.                 echo $d/\* >>$TMP/$EXCLUDE
  468.             fi
  469.         done
  470.         if [ "$use_patterns" = "YES" ]
  471.         then
  472.             $GREP -v "^#" $datadir/$configname/Exclude_Patterns >>$TMP/$EXCLUDE
  473.         fi
  474.     
  475.         if [ "$incremental" = "YES" ] ; then
  476.             touch -d "$datestamp" $TMP/$DATEFILE
  477.             findargs="$findargs -cnewer $TMP/$DATEFILE"
  478.         fi
  479.  
  480.         if [ "$use_patterns" = "YES" ]
  481.         then
  482.  
  483.         
  484.         $GREP -v "^#"  $datadir/$configname/Include_Patterns \
  485.     | $SED '1,$ s/^\(.*\)$/-or -path ".\/\1"/g' \
  486.     | tr "\n\r" "  " \
  487.     | $SED '1,$ s/^-or //g
  488.         1,$ s/^\(.*\)$/\\( \1 \\)/g' >$TMP/$TMPFILE
  489.  
  490.  
  491.             opt1=`cat $TMP/$TMPFILE`
  492.             if [ "$opt1" != "" ]
  493.             then
  494.                 findargs="$findargs -a $opt1 "
  495.             fi
  496.             
  497.  
  498.               $GREP -v "^#" $datadir/$configname/Exclude_Patterns \
  499.             | $SED '1,$ s/^\(.*\)$/-or -path ".\/\1"/g' \
  500.             | tr "\n\r" "  " \
  501.             | $SED '1,$ s/^-or //g
  502.                 1,$ s/^\(.*\)$/\\( \1 \\)/g' >$TMP/$TMPFILE
  503.  
  504.             opt2=`cat $TMP/$TMPFILE`
  505.             if [ "$opt2" != "" ]
  506.             then
  507.                 opt2=" \( -not $opt2 \) "
  508.                 findargs="$findargs -a $opt2 "
  509.             fi
  510.         fi
  511.         
  512.         # always:
  513.         
  514.         cat $TMP/$EXCLUDE \
  515.         | $SED '1,$ s/^\(.*\)$/-or -path ".\/\1"/g' \
  516.         | tr "\n\r" "  " \
  517.         | $SED '1,$ s/^-or //g
  518.             1,$ s/^\(.*\)$/\\( \1 \\)/g' >$TMP/$TMPFILE
  519.         opt3=`cat $TMP/$TMPFILE`
  520.         if [ "$opt3" != "" ]
  521.         then
  522.             opt3=" \( -not $opt3 \) "
  523.             findargs="$findargs -a $opt3 "
  524.         fi
  525.     fi
  526.         
  527.  
  528.     if [ $local = YES ] ; then
  529.         findargs="$findargs -xdev"
  530.     fi
  531.     if [ $directoriesonly = YES ] ; then
  532.         findargs="$findargs -type d"
  533.     fi
  534. }
  535.  
  536. create_dir_list()
  537. {
  538.     echo >$TMP/$DIRLISTFILE
  539.     echo >$TMP/$TARLISTFILE
  540.  
  541.     build_find_arguments
  542.  
  543.     cd $parent
  544.     files=.
  545.     set -f
  546.     echo find $files $findargs -fprintf $TMP/$DIRLISTFILE \"%p %s %u %g %Tc %m\\n\" -fprintf $TMP/$TARLISTFILE \"%p\\n\" >$TMP/$FINDFILE
  547.     . $TMP/$FINDFILE 2>/dev/null
  548.     set +f
  549. }
  550.  
  551. #
  552. # creates the file $TMP/$DIRLISTFILE where it keeps the names and information
  553. # about all the files to back up
  554. #
  555. build_dir_list()
  556. {
  557.     if [ $specifiedfilesonly = YES  ]
  558.     then
  559.         cp -f $datadir/$configname/Include_Files $TMP/$DIRLISTFILE 2>/dev/null
  560.         return
  561.     else
  562.         create_dir_list
  563.     fi
  564. }
  565.  
  566. set_compress()
  567. {
  568.     touch $TMP/$PHRASEFILE
  569.     pcompress=
  570.     puncompress=
  571.     tarcompress=
  572.     uncompress=
  573.     compress_program=
  574.     case $compression in
  575.         NONE)    compress=" cat " 
  576.             uncompress=" cat "
  577.             pcompress=" | cat "
  578.             puncompress=" | cat "
  579.             return
  580.             ;;
  581.         GZIP)    compress=" gzip -c "$compress_options" " 
  582.             compress_program="gzip"
  583.             cat >$TMP/$COMPRESSFILE <<_EOF_
  584. #!/bin/sh
  585. PATH="$PATH"
  586. gzip $compress_options \$* 2>/dev/null
  587. _EOF_
  588.             chmod +x $TMP/$COMPRESSFILE
  589.             tarcompress="--block-compress --use-compress-prog $TMP/$COMPRESSFILE"
  590.             uncompress=" gzip -c "$decompress_options" "
  591.             pcompress=" | $compress "
  592.             puncompress=" | $uncompress "
  593.             ;;
  594.             
  595.         COMPRESS) compress=" compress "$compress_options" "
  596.             compress_program="compress"
  597.         cat >$TMP/$COMPRESSFILE <<_EOF_
  598. #!/bin/sh
  599. PATH="$PATH"
  600. compress $compress_options \$* 2>/dev/null
  601. _EOF_
  602.             chmod +x $TMP/$COMPRESSFILE
  603.             tarcompress="--block-compress --use-compress-prog $TMP/$COMPRESSFILE"
  604.             uncompress=" compress "$decompress_options" "
  605.             pcompress=" | $compress "
  606.             puncompress=" | $decompress "
  607.             ;;
  608.             
  609.         PGP)     compress=" pgp -ef $pgpkey "$compress_options" 2>/dev/null"
  610.             compress_program="pgp"
  611.             cat >$TMP/$COMPRESSFILE <<_EOF_
  612. #!/bin/sh
  613. cd $TMP 2>/dev/null
  614. if [ "\$1" = "-d" ]
  615. then
  616.     opt=-d
  617.     pgp \$opt -f 2>/dev/tty 3<$TMP/$PHRASEFILE
  618. else
  619.     opt=-e
  620.     pgp \$opt -f $pgpkey  2>/dev/null
  621. fi
  622. _EOF_
  623.             chmod +x $TMP/$COMPRESSFILE
  624.             tarcompress="--block-compress --use-compress-prog $TMP/$COMPRESSFILE"
  625.             uncompress=" pgp -df $pgpkey $decompress_options "
  626.             pcompress=" | $compress "
  627.             puncompress=" | $uncompress "
  628.     esac
  629. }    
  630.  
  631. check_error()
  632. {
  633.     errno="$?"
  634.     check_error_cmd="$last_command"
  635.     last_command=
  636.  
  637.     if [ $errno != 0 ]    # error!
  638.     then
  639.         
  640.         if [ "$1" = "-dev" ]
  641.         then
  642.             echo "Device Error: it seems that an operation on the device
  643. $device has failed.
  644. " >$TMP/$TMPFILE
  645.             cat $TMP/$ERRFILE >>$TMP/$TMPFILE 2>/dev/null
  646.             cat $TMP/$TMPFILE >$TMP/$ERRFILE 
  647.         fi
  648.         if [ "$check_error_cmd" != "" ]
  649.         then
  650.             echo "This command has failed:" >>$TMP/$TMPFILE
  651.             echo "$check_error_cmd" >>$TMP/$TMPFILE
  652.         fi
  653.         
  654.         lines=`wc -l <$TMP/$ERRFILE`
  655.         if [ $lines -lt 2 ]
  656.         then 
  657.             echo "No Error message generated!" >$TMP/$ERRFILE
  658.             lines=2; 
  659.         fi
  660.         lines=`expr 8 + $lines`
  661.         
  662.         if [ $scheduled = YES ]
  663.         then
  664.             if [ -e $TMP/$MSGFILE ] ; then
  665.                 cat $TMP/$ERRFILE >>$TMP/$MSGFILE
  666.             else
  667.                 $TMP/$ERRFILE >&2
  668.             fi
  669.             return $errno
  670.         fi
  671.  
  672.         if [ "$last_command" != "" ]
  673.         then
  674.             echo "The command failed was:" >>$TMP/$ERRFILE
  675.             echo "$check_error_cmd" >>$TMP/$ERRFILE
  676.         fi
  677.         
  678.         $DIALOG --title " Program Execution Error " --msgbox "
  679. The last command returned a non-zero result ($errno).
  680. This indicates an error during its execution. The
  681. error message generated was:
  682.  
  683. `cat $TMP/$ERRFILE`" $lines 65
  684.         echo >$TMP/$ERRFILE
  685.     fi
  686.     return $errno
  687. }
  688.  
  689. #
  690. # afio 2.4.1 has a nasty bug, restoring the gzip program prevents it from
  691. # any further restoration of compressed files. As it does not notice this,
  692. # it will happily truncate all these files and report "Backup successful" :-)
  693. #
  694. # Therefore: save all critical programs in $TMP/$BINDIR and set the path there.
  695. # This is not perfectly save, but who would ever try to restore the programs
  696. # to exactly that path???
  697.  
  698. afio_bug_save_programs()    # must be called before doing a restore
  699. {
  700.     if [ ! -d $TMP/$BINDIR ]; then mkdir $TMP/$BINDIR; fi
  701.     check_error
  702.     # try to continue:
  703.     afio_bug_save_PATH="$PATH"
  704.     if [ ! -d $TMP/$BINDIR ]
  705.     then
  706.         mkdir $TMP/$BINDIR 2>$STDERR || check_error
  707.     fi
  708.     PATH="$TMP/$BINDIR:$PATH"
  709.     for i in $AFIO_PROGRAMS
  710.     do
  711.         place=`whereis $i | $SED "1,$ s/^$i: \(.*\)$/\1/g"`
  712.         if [ $? = 0 ]
  713.         then
  714.             cp $place $TMP/$BINDIR
  715.         fi
  716.     done
  717. }
  718. afio_bug_restore_path()
  719. {
  720.     PATH="$afio_bug_save_PATH"
  721. }
  722.  
  723. #
  724. # save important options that are going to be manipulated during
  725. # operation
  726. #
  727. save_options()
  728. {
  729.     old_compression="$compression"
  730.     old_use_multibuf="$use_multibuf"
  731.     old_multibuf_nblocks="$multibuf_nblocks"
  732.     old_multibuf_blksize="$multibuf_blksize"
  733.     old_multibuf_seq_info="$multibuf_seq_info"
  734. }
  735. #
  736. # restore previously saved options
  737. #
  738. restore_options()
  739. {
  740.     compression="$old_compression"
  741.     use_multibuf="$old_use_multibuf"
  742.     multibuf_nblocks="$old_multibuf_nblocks"
  743.     multibuf_blksize="$old_multibuf_blksize"
  744.     multibuf_seq_info="$old_multibuf_seq_info"
  745. }
  746.  
  747.  
  748. report()    # write to report file
  749. {
  750.     if [ "$CreateReport" != "YES" ]
  751.     then
  752.         return
  753.     fi
  754.     if [ "$1" = "--init" ]
  755.     then
  756.     tmp=`date`
  757.     if [ "$incremental" = "YES" ]
  758.     then
  759.         type="incremental"
  760.     else
  761.         type="full"
  762.     fi
  763.     cat <<_EOF_ >$TMP/$REPORTFILE
  764. KBackup Report File (KBackup Version $VERSION)
  765. =================================================================
  766.                KBackup is Copyright (C) 1996 by Karsten Ballueder
  767.  
  768. Using configuration:        $configname
  769. Creation date:              $tmp
  770. Backup type:                $type
  771. Parent directory of backup: $parent
  772. Compression mode:           $compression
  773. _EOF_
  774.     else
  775.         echo "$*" >>$TMP/$REPORTFILE
  776.     fi
  777. }
  778.  
  779. auto_rewind()    # rewind automatically if wanted
  780. {
  781.     if [ "$device_type" = "TAPE" ] 
  782.     then
  783.         if [ "$AutoRewind" = "YES" ]
  784.         then
  785.             InfoBox "Rewinding tape..."
  786.             last_command="mt rewind"
  787.             mt -f "$device" rewind 2>$STDERR
  788.             check_error -dev
  789.         else
  790.             MsgBox \
  791. "Please note that the tape does not
  792. get rewound automatically. If you 
  793. have written to or read from it, it
  794. might not be positioned at the be-
  795. ginning any longer.
  796. To rewind it, go into the Actions 
  797. Menu."
  798.         fi
  799.     fi
  800. }
  801.  
  802. uncompress_logfile()
  803. {
  804.     InfoBox "Uncompressing logfile..." 
  805.     old_compression="$compression"
  806.     logfile="$1"
  807.     filetype=`file $logfile`
  808.     if echo "$filetype" | $FGREP gzip >/dev/null ; then
  809.         compression=GZIP
  810.     else
  811.         if echo "$filetype" | $FGREP compress >/dev/null ; then
  812.             compression=COMPRESS
  813.         else
  814.             if echo "$filetype" | $FGREP text >/dev/null ; then
  815.                 compression=NONE
  816.             else
  817.                 setco=`$FGREP "compression" <$datadir/$dir/Config`
  818.                 echo $setco >$TMP/$TMPFILE
  819.                 . $TMP/$TMPFILE
  820.             fi
  821.         fi
  822.     fi
  823.     set_compress
  824.     cat < "$logfile" | $uncompress >$TMP/$TMPFILE
  825. }
  826.